<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class Singleton{
            constructor(name){
                this.name = name;
                this.instance = null;
            }

            getName(){
                console.log(this.name);
            }

            static getInstance(name){
                if(!this.instance){
                    this.instance = new Singleton(name);
                }

                return this.instance;
            }
        }

        let xiaoming = Singleton.getInstance('xiaoming');
        let xiaohong = Singleton.getInstance('xiaohong');
        xiaoming.getName();
        xiaohong.getName();
        console.log(xiaoming===xiaohong);
    </script>
</body>
</html>